package cn.kgc.flightdemo01.service;


import cn.kgc.flightdemo01.mapper.CityMapper;
import cn.kgc.flightdemo01.mapper.FlightMapper;
import cn.kgc.flightdemo01.mapper.ViewsFlightCityMapper;
import cn.kgc.flightdemo01.pojo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class FlightServiceImpl implements  FlightService {

    @Resource
    CityMapper cityMapper;
    @Resource
    FlightMapper flightMapper;
    @Resource
    ViewsFlightCityMapper viewsFlightCityMapper;


    @Override
    public List<ViewsFlightCity> selectAllFlight(Integer departurecity, Integer arrivalcity) {
       List<ViewsFlightCity> flights=new ArrayList<>();
        if (departurecity!=0){
            ViewsFlightCityExample example=new ViewsFlightCityExample();
            ViewsFlightCityExample.Criteria criteria=example.createCriteria();
            criteria.andDeparturecityEqualTo(departurecity);
            criteria.andArrivalcityEqualTo(arrivalcity);
            flights= viewsFlightCityMapper.selectByExample(example);
        }else{
            flights= viewsFlightCityMapper.selectByExample(null);
        }
        return flights;
    }

    @Override
    public List<City> selectAll() {
        return cityMapper.selectByExample(null);
    }

    @Override
    public Integer SaveFlight(Flight flight) {
        return flightMapper.insertSelective(flight);
    }
}
